﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using HelloTipi.Api;
using Windows.Data.Json;
using Windows.Storage;
using Windows.UI.ApplicationSettings;

namespace MetroTipi.Data
{
    public class FamiliesDataSource : MetroTipi.Common.BindableBase
    {
        private string username;
        private string password;
        private Object Families;

        ApiTxt apiTxt;

        public FamiliesDataSource()
        {
            if (ApplicationData.Current.RoamingSettings.Values.ContainsKey("Identifiant"))
            {
                username = (String)ApplicationData.Current.RoamingSettings.Values["Identifiant"];
                if (ApplicationData.Current.RoamingSettings.Values.ContainsKey("Password"))
                    password = (String)ApplicationData.Current.RoamingSettings.Values["Password"];
                else
                    SettingsPane.Show();
            }
            else
                SettingsPane.Show();

            apiTxt = new ApiTxt(username, password);
        }

        //public async void Initialize()
        //{
        //    Families = await apiTxt.getSitesASync();
        //}

        public async Task<IEnumerable<Object>> getFamilies()
        {
            Families = await apiTxt.getSitesASync();
            return Families as IEnumerable<Object>;
        }

        public async Task<IEnumerable<Object>> getAlbums(String site)
        {
            Object Albums = await apiTxt.getAlbumsASync(site);
            return Albums as IEnumerable<Object>;
        }

        public async Task<IEnumerable<Object>> getPhotos(String site, String album)
        {
            Object Photos = await apiTxt.getPhotosASync(site, album);
            return Photos as IEnumerable<Object>;
        }
        
    }
}
